function wxpay(app, orderId, redirectUrl) {
  wx.request({
    url: app.globalData.host + '/api/wechat/pay',
    data: {
      uid: app.globalData.userInfo.Uid,
      storeId: app.globalData.storeId,
      oid: orderId
    },
    success: function (res) {
      console.log('api result:');
      console.log(res.data);
      if (res.data.Code == 0) {
        // 发起支付
        wx.requestPayment({
          timeStamp: res.data.Data.timeStamp,
          nonceStr: res.data.Data.nonceStr,
          package: 'prepay_id=' + res.data.Data.prepayId,
          signType: 'MD5',
          paySign: res.data.Data.paySign,
          fail: function (aaa) {
            wx.showToast({ title: '支付失败:' + aaa })
            wx.redirectTo({
              url: redirectUrl
            });
          },
          success: function () {
            wx.showToast({ title: '支付成功' })
            wx.redirectTo({
              url: redirectUrl
            });
          }
        })
      } else {
        wx.showToast({ title: '服务器忙' + res.data.Code })
        wx.redirectTo({
          url: redirectUrl
        });
      }
    }
  })
}
// 现金充值
function wxcashpay(app, orderId, redirectUrl) {
  wx.request({
    url: app.globalData.host + '/api/WeChat/CashPay',
    data: {
      storeId: app.globalData.storeId,
      uid: app.globalData.userInfo.Uid,
      oid: orderId
    },
    success: function (res) {
      if(res.data.Code == 0){
        //发起支付
        wx.requestPayment({
          timeStamp: res.data.Data.timeStamp,
          nonceStr: res.data.Data.nonceStr,
          package: 'prepay_id=' + res.data.Data.prepayId,
          signType: 'MD5',
          paySign: res.data.Data.paySign,
          success: function (res) {
            wx.showToast({ title: '支付成功'})
            wx.redirectTo({
              url: redirectUrl
            });
          },
          fail: function (aaa) {
            wx.showToast({ title: '支付失败:' + aaa})
            wx.redirectTo({
              url: redirectUrl
            });
          }
        })
      }
      else{
        wx.showToast({ title: '服务器忙' + res.data.Code })
        wx.redirectTo({
          url: redirectUrl
        });
      }
    }
  })
}
module.exports = {
  wxpay: wxpay,
  wxcashpay: wxcashpay
}
